<?php
header("Content-Type: text/html; charset=utf-8"); 

require_once("config.inc.php");
require_once(COMM_PATH."book.php");
require_once(COMM_PATH."paging.php");
$book = new Book();
if ($_GET['CP']){
	$Cate = $_GET['CP'];
	$cateDataList = $book->getInfo($Cate, $book->_CATEGORY);
	if($cateDataList){
		$CP =  $cateDataList[0]['cate_name'];
	}else{
		require('404.php');
        @header('HTTP/1.1 404 Not Found');
        @header('Status: 404 Not Found');
        exit;
	}
}else{
	$Cate = 0;
	$CP = "首页";
}
if ($_GET['P']){
	$pageNum = $_GET['P'];
}else {
	$pageNum = 1;
}
//查询
if ($_GET['S']){
	$searchKey = $_GET['S'];
}else{
	$searchKey = "";
}
$searchKey = trim($searchKey);
$pageNum = trim($pageNum);
$Cate = trim($Cate);

$total = $book->seachbookByCateTotal($Cate,$searchKey);
$booList = $book->seachbookByCate($Cate,$searchKey,$pageNum);
$page = new PageInfo($pageNum,$total,20);

?>
<?php include_once 'top.php';?>

<div class="b_lofter">
	
	<div class="show_book">
    	<div class="center">
			<div class="inline-block-center page-title">
				<div class="line-separator linen right"></div><div class="line-separator linen left"></div>
				<h1 class="title_h1">
				<?php if($searchKey=="" || $searchKey == null){
					if($Cate==0){
						echo "<span>最新发布</span>";
					}else{
						echo "分类目录：<span>$CP</span>"; 
					} 
					
				}else {
					echo "搜索关键字：<span>$searchKey</span>"; 
				}?>
				</h1>
			</div>
		</div>
        <div class="books fn-clear">
        	<?php 
        	if($booList){
        		foreach ($booList as $key => $value){
        	?>
        	<div class="book_items"><a href="ReadList.php?BID=<?php echo $value['BID']?>" class="tooltip" title="<strong>《<?php echo $value['bookName']?>》</strong> 作者：<?php echo $value['author']?>"><img src="<?php echo INCLUDE_WEB."IMAGE_FILE/min/".$value["imagePath"];?>" /></a></div>
        	<?php 
        		}
        	}else{
        		echo "<div class=\"center\">呀！没找到诶。<br/>&nbsp;&nbsp;&nbsp;&nbsp;按 <a href=\"Contact.php\" title=\"留言\">这里</a> 给我们留言吧，我们会尽快加上去的，谢谢！</div>";
        	} ?>
        	
        </div>
        <div id="pagination">
        	<div class="pages">
        		<?php echo $page->showpagination($Cate,$searchKey);?>
        	</div>
        	 
        </div>
    </div>
</div>


<?php include_once 'footer.php';?>

<script type="text/javascript">
<!--
$(function(){
	/**
	*鼠标显示标题作者
	**/
	var x = 10;  
	var y = 20;
	$("a.tooltip").mouseover(function(e){
		this.myTitle = this.title;
		this.title = "";	
		var tooltip = "<div id='tooltip'>"+ this.myTitle +"</div>"; //创建 div 元素
		$("body").append(tooltip);	//把它追加到文档中
		$("#tooltip")
			.css({
				"top": (e.pageY+y) + "px",
				"left": (e.pageX+x)  + "px"
			}).show("600");	  //设置x坐标和y坐标，并且显示
	}).mouseout(function(){		
		this.title = this.myTitle;
		$("#tooltip").remove();   //移除 
	}).mousemove(function(e){
		$("#tooltip")
			.css({
				"top": (e.pageY+y) + "px",
				"left": (e.pageX+x)  + "px"
			});
	});

	/**
	*分页跳转
	**/
	$("#B_pageJump").click(function(){
		var p = $.trim($("#pageJumpto").val());
		var bigest = $("#bigest").val();
		if(!isNumber(p)){
			alert("必需输入数字");
			return false;
		}else{
			if(Number(p)>Number(bigest)){
				alert("输入的数字超过了最大页数");
				return false;
			}
		}
		var con = $("#condition").val();
		document.location.href = "?P="+p+con;
	});
	//绑定enter键
	$('#pageJumpto').keydown(function(e){
		if(e.keyCode==13){
			var p = $.trim($("#pageJumpto").val());
			var bigest = $("#bigest").val();
			if(!isNumber(p)){
				alert("必需输入数字");
				return false;
			}else{
				if(Number(p)>Number(bigest)){
					alert("输入的数字超过了最大页数");
					return false;
				}
			}
			var con = $("#condition").val();
			document.location.href = "?P="+p+con;
		}
	});	
});

function isNumber(oNum) 
{ 
	if(!oNum) return false; 
	var strP=/^\d+(\.\d+)?$/; 
	if(!strP.test(oNum)) return false; 
	try{ 
		if(parseFloat(oNum)!=oNum) return false; 
	}catch(ex) { 
		return false; 
	} 
	return true; 
}
//-->
</script>
